<template>
  <h2 style="text-align: center">用户注册</h2>
  <a-form :model="form" :style="{ width: '600px' }" @submit="handleSubmit">
    <a-form-item field="userAccount"  label="用户名">
      <a-input
          v-model="form.userAccount"
          placeholder="请输入用户名"
      />
    </a-form-item>
    <a-form-item field="userPassword" tooltip="密码不能小于8位数" label="密码">
      <a-input-password v-model="form.userPassword" placeholder="请输入密码" />
    </a-form-item>
      <a-form-item field="checkPassword"  label="确认密码">
        <a-input-password v-model="form.checkPassword" placeholder="请输入密码" />
      </a-form-item>
      <a-form-item>
      <a-space size="large">
        <a-button  type="primary" style="width: 120px" html-type="submit">注册</a-button>
      </a-space>
    </a-form-item>
  </a-form>
</template>

<script setup lang="ts">
import { reactive } from 'vue';
import {UserControllerService, UserLoginRequest} from "../../../generated";
import {useRouter} from "vue-router";
import {useStore} from "vuex";
import message from "@arco-design/web-vue/es/message"

const route = useRouter()
const store = useStore()
const form = reactive({
  userAccount :"",
  userPassword : "",
  checkPassword : ""
})

/**
 * 提交表单
 */
const handleSubmit = async () => {
  const res = await UserControllerService.userRegisterUsingPost(form);
  //登录成功
  if (res.code === 0) {
   message.success("注册成功")
    route.push({
      path: '/user/login',
      replace: true
    })
  } else {
    message.error("注册失败",res.msg)
  }
}
const goPage = () =>{
  route.push({
    path:'/user/register'
  });
}
</script>

